let obj ={
    arr : [1,2,3],
    length:3,
    // [Symbol.iterator]:Array.prototype[Symbol.iterator]
    [Symbol.iterator](){
        let index = 0;
        let self = this;
        return {
            next(){
                if(index < self.arr.length){
                    return {value:self.arr[index++],done:false};
                }else{
                    return {value:undefined,done:true} ;
                }
            }
        }
    }
}
for(let x of obj){
    console.log(x);
}


function Obj(value) {
    this.value = value;
    this.next = null;
  }
  
  Obj.prototype[Symbol.iterator] = function() {
    var iterator = { next: next };
  
    var current = this;
  
    function next() {
      if (current) {
        var value = current.value;
        current = current.next;
        return { done: false, value: value };
      } else {
        return { done: true };
      }
    }
    return iterator;
  }
  
  var one = new Obj(1);
  var two = new Obj(2);
  var three = new Obj(3);
  
  one.next = two;
  two.next = three;
  
  for (var i of one){
    console.log(i); // 1, 2, 3
  }